#pragma once

#include <muduo/net/TcpClient.h>
#include <muduo/net/EventLoop.h>
#include <muduo/base/Logging.h>
using namespace muduo;
using namespace muduo::net;
class MyTcpClient : private muduo::net::TcpClient {
public:
    MyTcpClient(const InetAddress& serverAddr);

    void ConnectCallBack(const TcpConnectionPtr &conn);

    void MessageCallBack(const TcpConnectionPtr& ptr,
                         Buffer* buf,
                         Timestamp);

    void Send(const std::string &msg);

    void Send(const char *buf, int len);

    bool Alive() { return is_alive_; }
    void Loop() { getLoop()->loop();}
    void Connect() { TcpClient::connect(); }
    void DisConnect() { TcpClient::disconnect(); }
    void Stop() { TcpClient::stop(); }

    virtual void OnConnect() = 0;

    virtual void OnConnectClose() = 0;
    // 返回处理了多少长度
    virtual int OnMessage(std::string &&data) = 0;
 private:
    bool is_alive_ = false;
};